package com.byzk.p2p.admin.system.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.byzk.p2p.admin.base.controller.AdminBaseController;
import com.byzk.p2p.admin.base.util.JsonMsg;
import com.byzk.p2p.admin.system.dto.SystemConfig;
import com.byzk.p2p.admin.system.service.SystemService;

@Controller
@RequestMapping("/admin/system")
public class SystemController extends AdminBaseController {
	
	@Autowired
	private SystemService systemService;
	
	@RequestMapping("/config")
	public String systemConfig(Model model){
		SystemConfig configList=systemService.listSystemConfig();
		model.addAttribute("config",configList);
		return ftl(Thread.currentThread().getStackTrace());
	}
	
	@RequestMapping("/config/save")
	@ResponseBody
	public String saveConfig(@RequestBody SystemConfig config){
		try {
			config.setCreateTime(new Date());
			systemService.saveOrUpdate(config);
			super.printJSON(new JsonMsg(-1,"操作成功"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
